package com.tensquare.sms.listener;

import com.aliyuncs.exceptions.ClientException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tensquare.sms.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: WangYaWei
 * @description:
 * @create: 2019-08-23 09:35
 **/
@Component
@RabbitListener(queues = "sms")
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    @Value("${aliyun.sms.register_template_code}")
    private String register_template_code;

    @Value("${aliyun.sms.sign_name}")
    private String sign_name;

    @RabbitHandler
    public void sendRedisterSms(Map<String, Object> map) throws ClientException, JsonProcessingException {
//        String content = "{\"product\": \"tensquare\", \"code\": \""+map.get("code")+"\"}";
        Map<String, Object> params = new HashMap();
        params.put("product", "tensquare");
        params.put("code", map.get("code"));
        ObjectMapper objectMapper = new ObjectMapper();
//        SendSmsResponse response = smsUtil.sendSms((String) map.get("mobile"), register_template_code, sign_name, content);
        System.out.println("短信验证码: " + map.get("code"));
        System.out.println("发送的手机号码" + map.get("mobile"));
    }
}
